//
//  NestTableViewCell.m
//  DA_V
//
//  Created by 中亿世联前台 on 15/5/10.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "NestTableViewCell.h"
#import "LineListView.h"
#import "LineView.h"
#import "ShoppingImageScrollView.h"
#import "InterFace.h"
#import "UIViewAdditions.h"
#import "NextZiDongChanShengListView.h"
#import "MyListModel.h"

#import "CarModel.h"
#import "ShoppingImageView.h"
#import "UIImageView+WebCache.h"
@implementation NestTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView*lineview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1)];
        lineview.backgroundColor = BackColor;
        
        [self.contentView addSubview:lineview];
        
        
        UIView *aview = [[UIView alloc]initWithFrame:CGRectMake(0, lineview.bottom, SCREEN_WIDTH, 10)];
        [self.contentView addSubview:aview];
        
        //订单号
        self.listNumber = (LineListView *)[[[NSBundle mainBundle] loadNibNamed:@"GeRen_xibs" owner:self options:nil] objectAtIndex:6];
        self.listNumber.frame = CGRectMake(10, aview.bottom, SCREEN_WIDTH-20, 70);
        self.listNumber.address.hidden = YES;
        [self.contentView addSubview:self.listNumber];
        
        
        
        //线条
        UILabel *lineView = [[UILabel alloc] initWithFrame:CGRectMake(10, self.listNumber.bottom-10, SCREEN_WIDTH-20, 1)];
        lineView.backgroundColor = LineColor;
        
        [self.contentView addSubview:lineView];
        
        //商品滑动图片
        CGRect rect = CGRectMake(0, lineView.bottom , SCREEN_WIDTH, (SCREEN_WIDTH-50) / 3.0+40);
//        self.shoppingImageScrollView = [ShoppingImageScrollView  soppingImageScrollViewWithFrame:rect data:array];
        self.shoppingImageScrollView = [[UIScrollView alloc] initWithFrame:rect];
        
        [self.contentView addSubview:self.shoppingImageScrollView];
        
        //线条
        UILabel *lineView2 = [[UILabel alloc] initWithFrame:CGRectMake(10, self.shoppingImageScrollView.bottom+5, SCREEN_WIDTH-20, 1)];
        lineView2.backgroundColor = LineColor;
        [self.contentView addSubview:lineView2];
        
        self.zidongChanShengListView =[[[NSBundle mainBundle] loadNibNamed:@"Shopping_list_xibs" owner:self options:nil] objectAtIndex:10];
        self.zidongChanShengListView.frame = CGRectMake(10, lineView2.bottom+5, SCREEN_WIDTH-20, 50);
        [self.contentView addSubview:self.zidongChanShengListView];
        
        //线条
        UILabel *lineView3 = [[UILabel alloc] initWithFrame:CGRectMake(0, self.zidongChanShengListView.bottom, SCREEN_WIDTH, 10)];
        lineView3.layer.borderColor = BackColor.CGColor;
        lineView3.layer.borderWidth = 1.0;
        lineView3.backgroundColor = LineColor;
        [self.contentView addSubview:lineView3];
        
    }
    return self;
}
//@property (weak, nonatomic) IBOutlet UILabel *xiaDanTIme;//下单时间
//@property (weak, nonatomic) IBOutlet UILabel *profitLabel;//利润
//
//@property (weak, nonatomic) IBOutlet UIButton *ziDongChanShengListBut;//自动产生补货订单
- (void)showMyCellView:(id)data arr:(NSArray *)arr{
    [self.shoppingImageScrollView removeAllSubviews];
    self.shoppingImageScrollView.contentSize = CGSizeMake(SCREEN_WIDTH*(arr.count/3.0), 100);
    for (int i = 0; i < [arr count]; i++) {
        
        
        ShoppingImageView *shoppingImageView = [[[NSBundle mainBundle] loadNibNamed:@"Shopping_Cart_Xib" owner:self options:nil] objectAtIndex:4];
        
        if ( [[arr[i] class] isSubclassOfClass:[CarModel class]]) {
            CarModel *carModel = arr[i];
            NSURL *url = [NSURL URLWithString:carModel.ThumbPath];
            shoppingImageView.shoppingNumBer.text = [NSString stringWithFormat:@"X%@",carModel.Number];
            shoppingImageView.zeKouJia.text = [NSString stringWithFormat:@"¥%.1f",carModel.MarketAmount.floatValue];
            [shoppingImageView.shoppingImag sd_setImageWithURL:url placeholderImage:nil];
            shoppingImageView.shoppingName.text = carModel.ProductName;
        }
        if ( [[arr[i] class] isSubclassOfClass:[MyListModel class]]) {
            MyListModel *carModel = arr[i];
            NSURL *url = [NSURL URLWithString:carModel.ThumbPath];
            shoppingImageView.shoppingNumBer.text = [NSString stringWithFormat:@"X%@",carModel.BuyAmount];
            shoppingImageView.zeKouJia.text = [NSString stringWithFormat:@"¥%.1f",carModel.DiscountPriceAmount.floatValue];
            [shoppingImageView.shoppingImag sd_setImageWithURL:url placeholderImage:nil];
            shoppingImageView.shoppingName.text = carModel.ProductName;
        }
        
        shoppingImageView.frame = CGRectMake(i * SCREEN_WIDTH / 3.0 + 10 , 10, (SCREEN_WIDTH-50) / 3.0, (SCREEN_WIDTH-50) / 3.0+30);
 
        [self.shoppingImageScrollView addSubview:shoppingImageView];
    }
    
    MyListModel *listModel = data;
    self.listNumber.listNum.text = [NSString stringWithFormat:@"%@",listModel.MasterOrderID];
    self.listNumber.allPrace.text = [NSString stringWithFormat:@"(¥%.1f)",listModel.TotalAmount.floatValue];
    self.listNumber.zheKouPrace.text = [NSString stringWithFormat:@"¥%.1f",listModel.DiscountAmount.floatValue];
    //    self.shoppingImageScrollView
    self.zidongChanShengListView.xiaDanTIme.text = [NSString stringWithFormat:@"%@",listModel.AddTime];
    self.listNumber.address.text= listModel.AddressDetail;
    self.listNumber.name.text = [NSString stringWithFormat:@"收货人:%@",listModel.CustomerName];
    self.listNumber.phoneNum.text = [NSString stringWithFormat:@"电话:%@",listModel.PhoneNumber];
    self.zidongChanShengListView.profitLabel.text = [NSString stringWithFormat:@"¥%@",listModel.Profit];
    self.zidongChanShengListView.ziDongChanShengListBut.userInteractionEnabled = YES;
    if ([[NSString stringWithFormat:@"%@",listModel.IsMakeup]isEqualToString:@"1"]) {
        [self.zidongChanShengListView.ziDongChanShengListBut setTitle:@"产生自动补货订单" forState:UIControlStateNormal];;
    } else{
      [self.zidongChanShengListView.ziDongChanShengListBut setTitle:@"没有产生自动补货订单" forState:UIControlStateNormal];;
    }
}

@end
